29. Select, where, and order by

SELECT, WHERE, and ORDER_BY

The SQL/SQLite Commands Cheat Sheet can be accessed here. It is also available from the Resources Tab.


Use the following SQL commands to make sure your pets table within the shelter.db matches the one in this demo:

  CREATE TABLE pets (
       _id INTEGER PRIMARY KEY AUTOINCREMENT,
       name TEXT NOT NULL,
       breed TEXT,
       gender INTEGER NOT NULL,
       weight INTEGER NOT NULL DEFAULT 0);

  INSERT INTO pets (name, breed, gender, weight) VALUES ( "Tommy", "Pomeranian", 1, 4);
  INSERT INTO pets (name, breed, gender, weight) VALUES ("Garfield", "Tabby", 1, 14);
  INSERT INTO pets (name, breed, gender, weight) VALUES ("Binx", "Bombay", 1, 6);
  INSERT INTO pets (name, breed, gender, weight)  VALUES ( "Lady", "Cocker Spaniel", 2, 14);
  INSERT INTO pets (name, breed, gender, weight) VALUES ("Duke", "Unknown", 1, 70);
  INSERT INTO pets (name, breed, gender, weight) VALUES ("Cat", "Tabby", 0, 7);
  INSERT INTO pets (name, breed, gender, weight) VALUES ("Baxter", "Border Terrier", 1, 8);
  INSERT INTO pets (name, gender, weight) VALUES ("Arlene", 2, 5);

QUESTION:

Select just the name and weight from the male pets, and order by weight with the highest weight at the top.

Paste the command you use here:

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer

Solution

SELECT, WHERE, and ORDER_BY